class Address < ActiveRecord::Base
  
  def Address.construct_from_html(some_html)
    post_code, line_1, line_2, line_3, line_4 = nil
    line_normalised_html= some_html.gsub(/<br\s*\/>/,"\n").gsub(/\r\n/,"\n").gsub(/\n+/,"\n")
    lines= line_normalised_html.split(/\n/)
    
    post_code= lines.last
    if lines.length > 0 
      lines.slice!(lines.length-1, 1)
      line_1= lines[0] if lines.length >0
      line_2= lines[1] if lines.length >1
      line_3= lines[2] if lines.length >2
      line_4= lines[3] if lines.length >3
    end
    puts "Discarding part of the address too many lines" if lines.length > 4
    return Address.new(:post_code=>post_code, :line_1=>line_1, :line_2=>line_2, :line_3=>line_3, :line_4=>line_4)
  end
end
